Available: March 31
Due: Wednesday, Apr 10, 22:00.
This assignment is to be done in TEAMS
OF TWO PEOPLE. The assignment should be submitted only once by a
member of your team, but please ensure that the identification material
contains the information for both team members.
For this assignment, classes should be in files with names that match the name
of the class. Make sure the method names are exactly the ones specified, because
the marking will be done with JUnit tests.
In this question, you will create a class User that will store information about the users of an online service similar to EBay. The users can sell items (register items for sales), other users can bid for these items, and each item will be sold to the user that offers the highest price during the bidding process.
See the UML diagram for the class User (UML diagrams specify the attributes of a class and their types and the method headers that you should use in your Java code) in the file A5_uml.pdf
Attributes:
User objects will store the following information for each user:
Constructors:
As a User object is created, a value should be supplied for the name, the login, and the initial password.
Here is the constructor header:
Accessors and Modifiers:
Public accessor methods should be available for the name and login. A public modifier method should be available for the name. Here are the method headers:
Additional methods
There should also be a method that compares a password entered by the user with the stored password. This method should return true if the user entered the correct password, and false otherwise.
There should be a method to change the user’s password. A password change is only permitted if the old password can be given, so the two parameters are the entered password and a new password. The entered password is compared with the password stored inside the object. If the password is correct, then the new password replaces the previous password inside the object. To indicate that the operation was successful, the method should return true. If the entered password was incorrect, the password stored in the object should remain unchanged and the method should return false.
You should be very careful that a
user object never gives out the stored password.
Testing
Test your User class using the JUnit class UserTest.java. You can do more testing for yourself, but make sure that the tests from UserTest.java (without modification) run properly.
In this question, you will create a class Item that will store information about items that can be purchased.
See the UML diagram for the class Item in the file A5_uml.pdf
Individual Item objects will store the following information for each item:
There should also be accessor and modifier methods these two values (see the UML diagram for the method headers).
Testing
Test your Item class using the JUnit class ItemTest.java. You should do more testing for yourself, but make sure that the tests from ItemTest.java (without modification) run properly.
In this question, you will create a class Transaction that will store information about a specific online event that happens on your EBay-type server. When a user wants to sell or buy an item, this class will represent the association between a User object and an Item object that is involved in the transaction.
See the UML diagram for the class Transaction in the file A5_uml.pdf
Attributes:
There are some values that apply to all Transaction objects:
Individual Transaction objects will store the following information for each transaction:
Constructor:
The constructor header is as follows:
Each time a new Transaction object is created, the next highest confirmation number not previously used should be stored. The confirmation number for the very first Transaction object created should be 100.
Also at the time of creation, the User reference, the references to the Item object, the price, and the type of the transaction should be stored.
Accessors and Modifiers:
There should be public accessor methods for the confirmation number of each transaction, for its type, for its status (active or not), for the User associated with the transaction, for the Item, and for the price. There should be public modifier methods to allow changing the price and the status of a transaction.
Testing
Test your Transaction class using the JUnit class TransactionTest.java. You should do more testing for yourself, but make sure that the tests from TransactionTest.java (without modification) run properly.
In this question, you will create a class MyEBServer that will store the collection of transactions, execute the biddings and the final purchases, and print some summary statements.
See the UML diagram for the class MyEBServer the file A5_uml.pdf
Because we do not want to allow more than one collection of transactions, the class MyEBServer will use (private) static array variables to store references to different kinds of Transaction objects. This also means that no MyEBServer objects are created. With no MyEBServer objects, all variables and methods must be static.
The class stores pointers to three arrays of transactions: an array of proposed selling transactions named registeredSales, an array of bidding transactions named registeredBids, and an array of purchases (finalized sales). The maximum number of entries in any of these three arrays is given as parameter in the initialize method (the same size for all three arrays). There is also an integer variable for each of the three arrays, to store the actual number of transactions of each kind that took place.
The method initialize(...) should create capacity for a specified number of Transaction objects to be stored in each of the three arrays in the MyEBServer class. However, no Transaction objects are added at this time.
The method addItemToSell(...) will attempt to add a Transaction object of type SELL to the array registeredSales. It will call the constructor of the class Transaction to create the new transaction for the specified user, item, price, and type. If there is space to hold another Transaction object, the object should be added, and the number of registered sales should be incremented. If the array has no more room to store additional objects, an error message should be printed.
The method addBid(...) will attempt to add a Transaction object of type BID to the array registeredBids. It will call the constructor of the class Transaction to create the new transaction for the specified user, item, price, and type. If there is space to hold another Transaction object, the object should be added and the number of registered bids should be incremented. If the array has no more room to store additional objects, an error message should be printed.
The
method displayBidsForItem (...) displays
all the bids for a given item. It is useful when a new bidder wants to see what were the current bids, to be able to bid a higher price.
The
method getBidsForItem(Item item)
returns an array with all the BID transactions for the item. The array should
be of the right size (the number of bids, not longer). The method returns an
empty array if there are no bids for the item.
The
method getMaxBidForItem(Item item) returns the Transaction that
corresponds to the highest bid. The method return null if there are no bids for
the item.
The
method executePurchases( ) goes through all the selling
transactions in the array registeredSales. For each
active selling transaction (only the active ones), it goes through the bids
from the array registeredBids (only the active ones).
Then it chooses the highest bid and finalizes the purchase by adding a
transaction of type FINAL_SALE to the array of purchases (for the same item and
user as in the BID transaction, and status set to active). The status of the
respective selling and bidding transactions has to be made inactive. An item
should not be sold to a bidder that offers less than the asking price. In this
case the item is not sold, it remains in the register
of sales. Similarly, if there are no bids for an item, it will not be sold (not
until somebody bids for it).
The method displayPurchases( ) displays all the purchases
(finalized sales) that happened in the server. It displays only the prices
offered, separated by one space.
Testing
Test your MyEBServer class using the class A5Q4.java that should produce exactly the output A5Q4.txt. This class contains the main method with a sample run of the MyEBServer. You can run more tests for yourself, but make sure the class A5Q4.java (non-modified) produces the required output.